package com.kgcx.system.controller;

import com.kgcx.common.bean.ReturnData;
import com.kgcx.common.controller.BaseController;
import com.kgcx.common.utils.FileUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @author 吴刚林
 * @date 2017/11/17
 */
@Api(description = "文件接口", tags = "文件接口")
@RestController
@RequestMapping("file")
public class FileController extends BaseController {
    @ApiOperation(value = "上传文件", httpMethod = "POST", notes = "这是用来上传文件的接口，返回的UUID为文件的唯一标识符")
    @PostMapping("upload")
    public ReturnData<String> upload(@ApiParam(name = "file", value = "上传的文件"
            , required = true, allowMultiple = true) @RequestPart("file") MultipartFile file) throws IOException {
        return new ReturnData<>(FileUtils.uploadImg(file.getInputStream()));
    }
}
